<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>extendHex</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const extendHex = shortHex =>
            '#' +
            shortHex
                .slice(shortHex.startsWith('#') ? 1 : 0)
                .split('')
                .map(x => x + x)
                .join('');
        console.log(extendHex('#03f')); // '#0033ff'
        console.log(extendHex('05a')); // '#0055aa'
    </script>
</body>

</html>